<template>
  <div>
    <van-nav-bar title="我参与的" left-arrow @click-left="onClickLeft" />
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
        <van-cell
          v-for="(item,index) in lists"
          :key="index"
          is-link
          :title="item.title"
          :to="`/detail/${item.id}`"
        />
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import { mapActions, mapState, mapMutations } from "vuex";
export default {
  name: "part",
  data() {
    return {
      loading: false,
      finished: false,
      refreshing: false
    };
  },
  methods: {
    ...mapActions("part", ["GET_LIST"]),
    ...mapMutations("part", ["SET_LISTS", "SET_PAGE"]),
    onClickLeft() {
      this.$router.back();
    },
    onLoad() {
      setTimeout(() => {
        if (this.refreshing) {
          //   this.list = [];
          this.refreshing = false;
          this.SET_PAGE(0);
        }
        this.SET_LISTS();
        this.SET_PAGE(20);
        this.loading = false;
        if (this.lists.length == this.total) {
          this.finished = true;
        }
      }, 1000);
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false;

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    }
  },
  computed: {
    ...mapState("part", ["list", "lists", "total"])
  },
  mounted() {
    this.GET_LIST();
  }
};
</script>

<style scoped>
</style>